using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;

namespace BuildWheel
{
    public class ManiFestMgr : MonoBehaviour
    {
        // Start is called before the first frame update
        public string main_manifest = "main_manifest.json";
        public FileObject fileObject;

        IEnumerator Start()
        {
            if (fileObject == null)
            {
                var request = UnityWebRequest.Get($"{Application.streamingAssetsPath}/{main_manifest}");
                request.timeout = 5;
                yield return request.SendWebRequest();
                yield return 0;
                var str = request.downloadHandler.text;
                Debug.Log(request.result);
                Debug.Log(request.url);
                var ls = JsonConvert.DeserializeObject<List<ResData>>(str);
                request.Dispose();
                request = null;
                yield return 0;
                fileObject = new FileObject();
                fileObject.RuntimeRef(ls);
            }

            yield return 0;
            OnFinished();
        }

        void OnFinished()
        {
            fileObject.GenFileDicT();
            FoldersMgr.fileObject = fileObject;
            floadersTree.Ref(FoldersMgr.fileObject.root);
        }

        public ProjectTree floadersTree;
    }
}